<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <canvas id="canvas" style="box-shadow: 0 0 10px #000;"></canvas>
</body>

</html>

<script>
  var canvas = document.getElementById('canvas')
  var ctx = canvas.getContext('2d')

  canvas.width = 1024
  canvas.height = 512

  var img = new Image()
  img.src = '../asset/img/sky.png'

  var X = 0
  function move() {
    ctx.save()
    ctx.clearRect(0, 0, canvas.width, canvas.height)
    ctx.translate(-X, 0)
    ctx.drawImage(img, 0, 0)
    ctx.drawImage(img, canvas.width, 0)

    X++
    if (X >= canvas.width) {
      X = 0
    }
    ctx.restore()
    window.requestAnimationFrame(move)
  }

  img.onload = function () {
    move()
  }
</script>